<template lang="jade">
  div.view-wrapper
    el-card
      el-form(v-loading="loading",element-loading-text="获取数据中...",element-loading-spinner="el-icon-loading")
        el-row(:gutter="20")
          el-col(:span="3")
            el-form-item
              span.lbl-project.lbl-title 企业名称
          el-col(:span="10")
            el-form-item
              span.lbl-project.pull-left {{corporation.name}}
        el-row(:gutter="20")
          el-col(:span="3")
            el-form-item
              span.lbl-project.lbl-title 法人代表身份证
          el-col(:span="4")
            el-form-item
              img.img-thumbnail(alt="法人代表身份证正面",:src="corporation.id_card_front")
          el-col(:span="4")
            el-form-item
              img.img-thumbnail(alt="法人代表身份证正面",:src="corporation.id_card_reverse")
        el-row(:gutter="20")
          el-col(:span="3")
            el-form-item
              span.lbl-project.lbl-title 法人代表姓名
          el-col(:span="4")
            el-form-item
              span.lbl-project.pull-left {{corporation.legal_representative}}
          el-col(:span="3")
            el-form-item
              span.lbl-project.lbl-title 营业年限
          el-col(:span="4")
            el-form-item
              span.lbl-project.pull-left {{corporation.business_t}}
        el-row(:gutter="20")
          el-col(:span="3")
            el-form-item
              span.lbl-project.lbl-title 注册资本
          el-col(:span="4")
            el-form-item
              span.lbl-project.pull-left {{corporation.registered_capital || '暂无数据'}}
          el-col(:span="3")
            el-form-item
              span.lbl-project.lbl-title 企业规模
          el-col(:span="4")
            el-form-item
              span.lbl-project.pull-left {{corporation.scale}}
        el-row(:gutter="20")
          el-col(:span="3")
            el-form-item
              span.lbl-project.lbl-title 联系电话
          el-col(:span="4")
            el-form-item
              span.lbl-project.pull-left {{corporation.phone || '赞未录入'}}
        el-row(:gutter="20")
          el-col(:span="3")
            el-form-item
              span.lbl-project.lbl-title 资质政府附件
          el-col(:span="4")
            el-form-item
              span.lbl-project.pull-left.active-color 点击下载
        el-row(:gutter="20")
          el-col(:span="3")
            el-form-item
              span.lbl-project.lbl-title 营业执照注册号
          el-col(:span="4")
            el-form-item
              img.img-thumbnail(alt="营业执照注册号",:src="corporation.business_license_img")
        el-row(:gutter="20")
          el-col(:span="3")
            el-form-item
              span.lbl-project.lbl-title 注册地址
          el-col(:span="10")
            el-form-item
              span.lbl-project.pull-left {{corporation.detail_address}}
        el-row(:gutter="20")
          el-col(:span="3")
            span.invisible *
          el-col(:span="10")
            template(v-if="corporation.auth_status === 2")
              el-button(@click="doConfirm",type="primary",style="width:100px;height:35px",:loading="submitConfirm.status") {{submitConfirm.text}}
              el-button(@click="doReject",type="danger",style="width:100px;height:35px") 驳回审核
            el-button(@click="goBack",style="width:100px;height:35px") 返回
</template>

<script>
  import utilsApi from '@/api/utils'
  export default {
    name: 'AuditDetail',
    data: () => ({
      loading: false,
      cId: null,
      corporation: {},
      submitConfirm: {
        status: false,
        text: '确认审核'
      },
      submitReject: {
        text: '驳回审核',
        status: false
      }
    }),
    created () {
      this.cId = this.$route.params.uId
    },
    mounted () {
      this.loading = true
      utilsApi.getCurrentCorporation(this.cId).then(res => {
        this.loading = false
        if (res.data.data) {
          this.corporation = Object.assign({ }, this.corporation, res.data.data)
        }
      }, err => {
        this.loading = false
        this.$message({
          type: 'error',
          message: err.response.data.message
        })
      })
    },
    methods: {
      goBack () {
        this.$router.go(-1)
      },
      doConfirm () {
        this.$confirm('确定要审核？', '提示', {
          dangerouslyUseHTMLString: true,
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.auditCorporation(1)
        })
      },
      doReject () {
        this.$confirm('确定要驳回当前公司的申请？', '提示', {
          dangerouslyUseHTMLString: true,
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.auditCorporation(0)
        })
      },
      auditCorporation (status) {
        var type = 'submitConfirm'
        var resetText = '确认'
        if (!status) {
          type = 'submitReject'
          resetText = '驳回'
        }
        this[type].text = '提交中...'
        this[type].status = true
        utilsApi.authCorporation({companyId: this.cId, authStatus: status, type: 'auth'}).then(res => {
          this[type].text = `${resetText}审核`
          this[type].status = false
          if (res.data.errcode === 0) {
            this.$message({
              type: 'success',
              message: '审核成功!'
            })
            this.$router.go(-1)
          } else {
            this.$message({
              type: 'error',
              message: res.data.errmsg
            })
          }
        }, err => {
          this[type].text = `${resetText}审核`
          this[type].status = false
          this.$message({
            type: 'error',
            message: err.response.data.message
          })
        })
      }
    }
  }
</script>

<style lang="scss" scoped>
  @import "../../../assets/css/mixin";

  .lbl-title{
    font-size: 15px;
    font-weight: bold;
  }

  .img-thumbnail{
    width: 100%;
    border-radius: 5px;
  }

  .invisible{
    opacity: 0;
    visibility: hidden;
  }
  .active-color{
    color: $active-color;
  }
</style>
